import {
  Row,
  Col,
  Form,
  Input,
  Select,
  Modal
} from 'antd';
import SelectDeptTree from '@/components/SelectDeptTree';
const FormItem = Form.Item;
const { Option } = Select;

//新增表单
let getDeptTreeBySelectTree;
const CreateForm = Form.create()(props => {
  const { 
  	modalVisible, 
  	form, 
  	handleAdd, 
  	handleModalVisible,
  	dispatch,
	requestModelName,
  	selectDeptTree
  } = props;
  
  const selectedDeptTreeValue = (deptRecord) => {
		getDeptTreeBySelectTree = deptRecord;
	}
  
  const parentDeptTreeMethod = {
		dispatch,
		selectDeptTree,
		selectedDeptTreeValue,
		requestModelName
	}
  
  const okHandle = () => {
    form.validateFields((err, fieldsValue) => {
      if (err) return;
      form.resetFields();
      if(getDeptTreeBySelectTree) {
		fieldsValue.dept_id = getDeptTreeBySelectTree.triggerNode.props.dataRef.key;
		fieldsValue.dept_name = getDeptTreeBySelectTree.triggerNode.props.dataRef.title;
	  }
      handleAdd(fieldsValue);
    });
  };
  return (
    <Modal
width={800}
destroyOnClose
title="新增"
visible={modalVisible}
onOk={okHandle}
onCancel={() => handleModalVisible()}
>
<Form  layout="vertical">

    <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

        <Col  md={12} sm={24}>
	        <FormItem  label="名称">
	            {form.getFieldDecorator('post_name', {
	            rules: [{ required: true, message: '请输入岗位名称！', min: 1 }],
	            })(<Input placeholder="请输入" />)}
	        </FormItem>
        </Col>
				
		<Col  md={12} sm={24}>
	        <FormItem  label="部门">
	        	{form.getFieldDecorator('dept')(
               	<SelectDeptTree {...parentDeptTreeMethod} />
	          )}
	        </FormItem>
        </Col>

    </Row>
    <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

       	<Col md={12} sm={24}>
	        <FormItem label="状态">
	            {form.getFieldDecorator('enable',{
	            	initialValue: "1",
	            })(
	                <Select placeholder="请选择" style={{ width: '100%' }}>
	                		<Option value="1">可用</Option>
	                    <Option value="0">禁用</Option>
	                </Select>
	            )}
	        </FormItem>
        </Col>
				
        <Col  md={12} sm={24}>
	        <FormItem  label="描述">
	            {form.getFieldDecorator('post_description')(<Input placeholder="请输入" />)}
	        </FormItem>
        </Col>

    </Row>
</Form>
</Modal>
  );
});

export default CreateForm;


